export default function ({ $axios, redirect,$info,$error,$warn }) {
  $axios.onRequest(config => {
    if (process.server){
      $info(`[onRequest][url=${config.url}][method=${config.method}][data=${JSON.stringify(config.data)}]`)
      config.metadata = { startTime: new Date().getTime() }
    }
   
    return config
  })
  $axios.onResponse(response => {
    if (process.server){
      let endTime = new Date().getTime()
      let duration = endTime-response.config.metadata.startTime
      let res=response.config.url.includes('.json')?'':JSON.stringify(response.data)
      $info(`[onResponse][status=${response.status}][duration=${duration}][url=${response.config.url}][data=${response.config.data}][res=${res}]`)
      if (duration>500){
        $warn(`[onResponse][status=${response.status}][duration=${duration}][url=${response.config.url}][data=${response.config.data}][res=${res}]`)
      }   
    }
    return response.data
  })
  $axios.onResponseError(err => {
    if (process.server){
      $error(`[onResponseError][method=${err.config.method}][url=${err.config.url}][message=${err.message}][stack=${err.stack}]`)
    }

  })
}